﻿namespace ApiTemplate.WebApi
{
    /// <summary>
    /// 设置跨域
    /// </summary>
    public static class CorsSetup
    {
        /// <summary>
        /// 设置跨域
        /// </summary>
        /// <param name="services"></param>
        /// <param name="appSetting"></param>
        public static void AddCorsSetup(this IServiceCollection services, AppSetting appSetting)
        {
            //跨域设置
            string[] hosts = appSetting.AllowedHosts.Trim(',').Split(',');
            services.AddCors(options =>
            {
                options.AddPolicy("LimitRequests",
                    builder => builder
                    .WithOrigins(hosts)
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    );
            });
        }
    }
}
